#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
int edge[1000][1000];
int N;
int visited[1000];
int dist[1000];
int ans = 0;
void prim(int vex) {
	for (int i = 0; i < N; i++) {
		visited[i] = 0;
		dist[i] = edge[vex][i];
	}
	dist[vex] = 0;
	visited[vex] = 1;
	for (int i = 0; i < N; i++) {
		int minIndex = -1;
		int min = 1000;
		for (int j = 0; j < N; j++) {
			if (!visited[j] && min > dist[j]) {
				min = dist[j];
				minIndex = j;
			}
		}
		visited[minIndex] = 1;
		ans += min;
		for (int j = 0; j < N; j++) {
			if (!visited[j] && dist[j] > edge[minIndex][j]) {
				dist[j] = edge[minIndex][j];
			}
		}
	}
}
int main(){
	
	prim(0);
}